package com.example.data.factory.common.configer;

import com.example.data.factory.common.Interector.LoginIntorector;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

@Configuration
public class IntorectorConfig implements WebMvcConfigurer {

    private static final Logger logger = LoggerFactory.getLogger ( IntorectorConfig.class );

    @Resource
    private LoginIntorector loginIntorector;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        logger.info ( "Registering LoginIntorector..." );

        registry.addInterceptor ( loginIntorector )
                .excludePathPatterns (
                        "/personner/login", // 登录接口
                        "/swagger-ui/**",   // Swagger UI
                        "/v3/api-docs/**",  // API 文档
                        "/swagger-resources/**", // Swagger 资源
                        "/webjars/**",      // Webjars
                        "/doc.html/**",     // Knife4j 文档
                        "/static/**",       // 静态资源
                        "/css/**",          // CSS 文件
                        "/js/**",           // JS 文件
                        "/images/**"        // 图片资源
                )
                .addPathPatterns ( "/**" ) // 拦截所有路径
                .order ( 1 ); // 设置拦截器的优先级

        logger.info ( "LoginIntorector registered successfully." );
    }
}